package com.xiong.fan.proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JDKQuery implements InvocationHandler {

    private QueryService target;


    public Object getInstance(QueryService target){
        this.target=target;
        Class<? > clazz =target.getClass();
        return  Proxy.newProxyInstance(clazz.getClassLoader(),clazz.getInterfaces(),this);
    }


    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before");
        method.invoke(this.target,args);
        System.out.println("after");
        return null;
    }
}
